#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define ll long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define getBit(mask, k) (((mask) / pw[k]) % pw[1])
#define setBit(mask, k, l) (((mask) / pw[k + 1] * pw[1] + (l)) * pw[k] + ((mask) % pw[k]))
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define ff first
#define ss second 
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int inf = 1 << 28;
const ldb pi = fabsl(atan2l(0.0, -1.0));
using namespace std;

vector <ll> all;
class Range
{
	public:
		ll l,  r;
		int i;
		static inline bool cmpl(const Range &a, const Range &b)
		{
			return a.l < b.l || a.l == b.l && a.r < b.r;
		}
		static inline bool cmpr(const Range &a, const Range &b)
		{
			return a.r < b.r || a.r == b.r && a.l < b.l;
		}
};

vector <Range> sortedl;
vector <Range> sortedr;

ll K;
int n;
ll maxlen;

void load()
{
	cin >> n >> K;
	for (int i = 1; i <= 18; i++)
	{
		for (int j = 0; j < (1 << i); j++)
		{
			ll num = 0;
			for (int k = 0; k < i; k++)
			{
				if (j & (1 << k))
					num = num * 10 + 4;
				else num = num * 10 + 7;
			}
			all.pb(num);
		}
	}
	sort(all.begin(), all.end());
	cerr << all.size();
	maxlen = 1000000000ll *1000000000ll;
	Range range;
	for (int i = 0; i < n; i++)
	{
		scanf("%I64d%I64d", &range.l, &range.r);
		range.i = i;
		maxlen = min(maxlen, range.r - range.l);
		sortedl.pb(range);
		sortedr.pb(range);
	}
	sort(sortedl.begin(), sortedl.end(), Range :: cmpl);
	sort(sortedr.begin(), sortedr.end(), Range :: cmpr);
}

set <pair <ll, ll> > was;
#define left LEFT
#define right right_asdas
ll partl[123123];
ll partr[123123];
ll left[525123];
ll right[525123];


inline ll sum(ll a, ll b)
{
	if (a > 1000000000000000000ll || b > 1000000000000000000ll) return 1000000000000000001ll;
	if (a + b > 1000000000000000000ll) return 1000000000000000001ll;
	return a + b;
}
inline ll mul(ll a, ll b)
{
	if ((double)a * (double)b > 1e18) return 1000000000000000001ll;
	return a * b;
}



void solve()
{
/*
	for (int i = 0; i < n; i++)
	{
		cerr << sortedl[i].l << " " << sortedl[i].r << "\n";
	}
	cerr << "\n";
	for (int i = 0; i < n; i++)
	{
		cerr << sortedr[i].l << " " << sortedr[i].r << "\n";
	}
	cerr << "\n";
	*/
	int q = 0;
	for (int i = 0; i < n; i++)
	{
		if (i)
			partl[i] = sum(partl[i - 1], mul(i, (sortedr[i].r - sortedr[i - 1].r)));
		else partl[i] = 0;
		if (i)
			partr[n - i - 1] = sum(partr[n - i], mul(i, (sortedl[n - i].l - sortedl[n - i - 1].l)));
		else partr[n - i - 1] = 0;
	}
	for (int i = 0; i < all.size(); i++)
	{
		int l = 0;
		int r = n - 1;
		int mid, res = -1;
		while (l <= r)
		{
			mid = (l + r) >> 1;
			if (sortedr[mid].r < all[i])
			{
				res = mid;
				l = mid + 1;
			}
			else r = mid - 1;
		}
		if (res != -1)
			left[i] = sum(partl[res], mul(((ll)all[i] - sortedr[res].r), (ll) (res + 1)));
		l = 0;
		r = n - 1;
		res = -1;
		while (l <= r)
		{
			mid = (l + r) >> 1;
			if (sortedl[mid].l > all[i])
			{
				res = mid;
				r = mid - 1;
			}
			else l = mid + 1;
		}
		if (res != -1)
			right[i] = sum(partr[res], mul(sortedl[res].l - all[i], n - res));
		//cerr << left[i] << "\n";
	//	if (left[i] < 0) throw 42;
	//	if (right < 0) throw 42;

	}
	int res = 0;
	for (int i = 0; i < all.size(); i++)
	{
		while (q < all.size() && all[q] - all[i] <= maxlen) q++;
		q--;
		if (sum(left[q], right[i]) <= K && q - i + 1 > res)
		{
		//	cerr << all[i] << " " << all[q] << "\n";
		//	cerr << left[q] + right[i] << "\n";
			res = q - i + 1;
		}
	}
	cout << res;
}

#define file "d"
int main()
{
	#ifndef ONLINE_JUDGE
		freopen(file".in", "rt", stdin);
		freopen(file".out", "wt", stdout);
	#endif
	load();
	solve();
	return 0;
}
